package de.mhu.mandalaui.forms;

import de.mhu.mandalaui.Component;
import de.mhu.mandalaui.properties.PropertiesTable;
import de.mhus.lib.MException;
import de.mhus.lib.form.LayoutBuilderWithStack;
import de.mhus.lib.form.LayoutComposite;
import de.mhus.lib.form.LayoutDataElement;
import de.mhus.lib.form.LayoutElement;
import de.mhus.lib.form.LayoutRoot;
import de.mhus.lib.form.UiElement;
import de.mhus.lib.lang.MutableActivator;

public class MandalaFormBuilder extends LayoutBuilderWithStack<UiMandalaComposite> {

	private Component rootComposit;
	private PropertiesTable currentComposit;

	@Override
	public void createCompositStart(LayoutComposite arg0) {
		
	}

	@Override
	public void createCompositStop(LayoutComposite arg0) {
		
	}

	@Override
	public void createDataElement(LayoutDataElement element) throws MException {
		log().d("createDataElement", element);
		UiMandala ui = (UiMandala)element.getUi();
		ui.createUi(this);
	}

	@Override
	public void createRootStart(LayoutRoot root) {
		UiMandalaComposite ui = new UiMandalaComposite();
		root.setUi(ui);
		ui.createUi(this);
		currentComposit = ui.getTable();
		rootComposit = currentComposit;
		push(ui);
	}

	@Override
	public void createRootStop(LayoutRoot arg0) {
		pop();
	}

	@Override
	public void createSimpleElement(LayoutElement arg0) {
		
	}

	@Override
	public void initActivator(MutableActivator act) {
		act.addMap(UiElement.class,"text", UiText.class);
	}
	
	public PropertiesTable getCurrentTable() {
		return currentComposit;
	}

}
